# coding=utf-8
import re

COLOR_PATTERN = re.compile(r'^[0-9a-fA-F]{6}$')


class OptionType(object):
    SWITCH = 'switch'
    ENUM = 'enum'
    INT = 'int'
    FLOAT = 'float'
    COLOR = 'color'

    BUTTON = 'button'


MODIFIABLE_OPTION_TYPES = {
    OptionType.SWITCH,
    OptionType.ENUM,
    OptionType.INT,
    OptionType.FLOAT,
    OptionType.COLOR,
}
INTERACTIVE_OPTION_TYPES = {
    OptionType.BUTTON
}

VALUE_CHECK_MAP = {
    OptionType.SWITCH: lambda value, option: type(value) is bool,
    OptionType.ENUM: lambda value, option: type(value) is str and value in option['valid'],
    OptionType.INT: lambda value, option: type(value) is int and option['min'] <= value <= option['max'],
    OptionType.FLOAT: lambda value, option: type(value) is float and option['min'] <= value <= option['max'],
    OptionType.COLOR: lambda value, option: type(value) is str and COLOR_PATTERN.match(value),
}
""":type: dict[str, function]"""
